package com.everflourish.yeah100.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.TextView;

import com.everflourish.yeah100.R;

public class CircleTextView extends TextView {

    private int defStyle = Color.RED;
    private int mColor = 0;
    private Paint mPaint;

    public CircleTextView(Context context) {
        this(context, null);
        // TODO Auto-generated constructor stub
    }

    public CircleTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.CircleTextView);
        mColor = a.getColor(R.styleable.CircleTextView_circleColor, defStyle);
        a.recycle();
        initPain();
    }

    public CircleTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    private void initPain() {
        mPaint = new Paint();
        mPaint.setColor(mColor);
        mPaint.setStrokeWidth(5);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setAntiAlias(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        setTextColor(mColor);
        super.onDraw(canvas);
        int width = getWidth();
        int height = getHeight();
        RectF rectF = new RectF(mPaint.getStrokeWidth(),
                mPaint.getStrokeWidth(), width - mPaint.getStrokeWidth(),
                height - mPaint.getStrokeWidth());
        canvas.drawOval(rectF, mPaint);
    }

}
